package base2dev.web.pages.musics;

import musics.model.Artist;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import base2dev.core.model.Bag;
import base2dev.web.common.MasterPage;

public class Artists extends MasterPage {

	private static final long serialVersionUID = -172023293058228107L;

	@SpringBean(name = "artists")
	private Bag<Artist> artists;

	public void setArtists(Bag<Artist> artists) {
		this.artists = artists;
	}

	public Bag<Artist> getArtists() {
		return artists;
	}

	public Artists() {
		super("title");
	}

	 

	@Override
	public void setControls() {

		add(new DataView<Artist>("list", new ListDataProvider<Artist>(getArtists().getAll()) ){
			 
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(final Item<Artist> item) {
				final Artist a = item.getModelObject();

				item.add(new Label("artist.name"  , a.getName()));
		
				item.add(new Label("artist.nick" , a.getNickName()));
				item.add(new Label("artist.albuns" ,"" + 0));
				item.add(new Label("artist.songs" ,"" + 0));
				item.add(linkbtn(a));
				
			 
			}

			private Link linkbtn(final Artist a) {

				String path = a.getPhoto();
		 

				Link item =  new Link("actions")
	            {
	                @Override
	                public void onClick()
	                {
	                	 setResponsePage(new ArtistPage(a));
	                }
	            };

				item.add(new Label("artist.id"  , ""+a.getId()));
	            item.add(new WebMarkupContainer("artist.img").add(new SimpleAttributeModifier("src", path)));
				

				return item; 
				
			}
		});
	}
}